package com.qf.flashlib.base;

import org.greenrobot.eventbus.EventBus;

import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

/**
 * 2018/11/9 15:12
 */
public abstract class BasePresenter<V extends IView> implements IPresenter<V> {
    protected V mRootView;
    private CompositeDisposable mCompositeDisposable = new CompositeDisposable();

    @Override
    public void attachView(V mRootView) {
        this.mRootView = mRootView;
    }

    @Override
    public void detachView() {
        this.mRootView = null;
        if (mCompositeDisposable != null) {
            mCompositeDisposable.dispose();
            mCompositeDisposable = null;
        }
    }

    public void addSubscription(Disposable disposable) {
        mCompositeDisposable.add(disposable);
    }

    public void cancelRequest() {
        if (mCompositeDisposable != null) {
            mCompositeDisposable.dispose();
        }
    }

}
